package edu.guet.server.service;

import edu.guet.server.mapper.NoticeMapper;
import edu.guet.server.model.dto.NoticeDTO;
import edu.guet.server.model.vo.NoticeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    /**
     * 增加公告
     * @param noticeDTO
     * @return
     */
    public NoticeVO addNotice(NoticeDTO noticeDTO) {

        Integer semesterId = noticeDTO.getSemester_id();
        String noticeTitle = noticeDTO.getNotice_title();
        String noticeContent = noticeDTO.getNotice_content();

        noticeMapper.addNotice(semesterId, noticeTitle, noticeContent);

        NoticeVO noticeVO = new NoticeVO();
        noticeVO.setNotice_title(noticeTitle);
        noticeVO.setNotice_content(noticeContent);
        return noticeVO;
    }

    /**
     * 按照id找最新一条课堂公告
     * @param semesterId
     */
    public NoticeVO lastnotice(Integer semesterId) {
        return noticeMapper.findlastNoticeBysemesterId(semesterId);
    }

    public List<NoticeVO> selectNotice(Integer semesterId) {
        return noticeMapper.selectNotice(semesterId);
    }

    /**
     * 删除公告
     * @param noticeId
     */
    public void deleteNotice(Integer noticeId) {
        noticeMapper.deleteNotice(noticeId);
    }

    public Integer updateNotice(NoticeDTO noticeDTO) {
       return  noticeMapper.updateNotice(noticeDTO);
    }
}
